﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace Square.Activity.ActivityViewerTestWP
{
    [ToolboxItemAttribute(false)]
    public class ActivityViewerTestWP : Microsoft.SharePoint.WebPartPages.WebPart
    {
        SquareActivityViewer sav;
        RadioButtonList rblType;
        Button BtnQuery;
        SquareActivities aType;
        protected override void CreateChildControls()
        {
            rblType = new RadioButtonList();
            rblType.RepeatDirection = RepeatDirection.Horizontal;
            foreach (SquareActivities actType in Enum.GetValues(typeof(SquareActivities)))
            {
                if (actType.ToString().Contains("All"))
                {
                    rblType.Items.Add(actType.ToString());
                }
            }
            Controls.Add(rblType);

            BtnQuery = new Button();
            BtnQuery.Text = "조회";
            BtnQuery.Click += new EventHandler(BtnQuery_Click);
            Controls.Add(BtnQuery);

            sav = new SquareActivityViewer();
            
            Controls.Add(sav);

            base.CreateChildControls();
        }

        void BtnQuery_Click(object sender, EventArgs e)
        {
            aType = new SquareActivities();
            switch (rblType.SelectedValue)
            {
                case "DocAll": aType = SquareActivities.DocAll; break;
                case "MemoAll": aType = SquareActivities.MemoAll; break;
                case "PeopleAll": aType = SquareActivities.PeopleAll; break;
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            sav.SquareActivityType = aType;
        }
    }
}
